/* custom sprite class, abstraction layer for PIXI's sprite for now
 */
var dd_sprite = function(filename) {
	var sprite = PIXI.Sprite.from(filename);
	this.sprite = sprite;

	// automaticall add sprite to stage
	eng.app.stage.addChild(this.sprite);

	this.setWidth = function(val) {
		sprite.width = val;
	};

	this.setHeight = function(val) {
		sprite.height = val;
	};

	this.getWidth = function() {return sprite.width;}
	this.getHeight = function() {return sprite.height;}

	this.setAnchor = function(val) {
		sprite.anchor.set(val);
	};

	// get position
	this.getX = function() {return sprite.x;};
	this.getY = function() {return sprite.y;};
	this.getPosition = function() {return sprite.position;};

	// get position in a rectangle way
	this.getLeft = function() {return this.getX();}
	this.getTop = function() {return this.getY();}
	this.getRight = function() {return this.getX() +this.getWidth();}
	this.getBottom = function() {return this.getY() +this.getHeight();}

	// set position
	this.setX = function(val) {
		sprite.x = val;
	};

	this.setY = function(val) {
		sprite.y = val;
	};

	this.setVisible = function(val) {
		sprite.visible = val;
	};

	this.getVisible = function() {return sprite.visible;};
	this.getRotation = function() {return sprite.rotation};
	this.getRotationDegrees = function() {return this.getRotation() *180 /Math.PI;};

	this.setRotation = function(val) {
		sprite.rotation = val;
	};

	this.setRotationDegrees = function(val) {
		this.setRotation(val *Math.PI /180);
	};

	// physics
	this.collidesWith = function(sprite2) {
		return (this.getRight () > sprite2.getLeft() == this.getLeft() < sprite2.getRight ()
		&&      this.getBottom() > sprite2.getTop () == this.getTop () < sprite2.getBottom());
	};
};
